
import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author Administrator
 */
public class SendTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Socket kkSocket = null;
        OutputStream out = null;
        InputStream in = null;

        try {
            //kkSocket = new Socket("10.19.7.5", 10001);
            kkSocket = new Socket("127.0.0.1", 4444);
            out = kkSocket.getOutputStream();
            in = kkSocket.getInputStream();
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host: taranis.");
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to: taranis.");
            System.exit(1);
        }
        try {
         
            //in.read(cbuf);
            byte[] data = new byte[18];

            for (int i = 0; i < 18; i++) {
                data[i] = (byte) i;
            }

            data[0] = (byte) 0x06;
            data[1] = (byte) 0x08;
            data[2] = (byte) 0x00;
            data[3] = (byte) 0x01;
            data[4] = (byte) 0x01;
            data[5] = (byte) 0x00;
            data[6] = (byte) 0x00;
            data[7] = (byte) 0x00;
            data[8] = (byte) 0x00;
            data[9] = (byte) 0x12;
            data[10] = (byte) 0x06;
            data[11] = (byte) 0x13;///日
            data[12] = (byte) 0x19;///时
            data[13] = (byte) 0x05;///分
            data[14] = (byte) 0x00;
            data[15] = (byte) 0x00;
            data[16] = (byte) 0x00;
            data[17] = (byte) 0x9E;
//            data[18] = (byte) 0x02;
//            data[19] = (byte) 0x00;
//            data[20] = (byte) 0x00;
//            data[21] = (byte) 0x00;
//            data[22] = (byte) 0x00;
//            data[23] = (byte) 0x00;
//            data[24] = (byte) 0x00;
//            data[25] = (byte) 0x00;
            //data[26] = (byte) 13;data[27] = (byte) 10;

            out.write(data);
            out.flush();                            
            
            out.write(data);
            
            System.out.println("ok1");
            byte [] dataReturn = new byte[9];
            kkSocket.setSoTimeout(30000);
            int l = in.read(dataReturn);
            System.out.println("length:" + l);
            for (int j = 0; j < l; j++) {
                System.out.println((byte) dataReturn[j]);
            }
            System.out.println("ok2");
            
            out.close(); 
            in.close();
            System.out.println("exit");

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
        }
    }
}
